/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.C575;
import queenb.net.entitybean.K300;
import queenb.net.entitybean.Q000;
import queenb.web.crm.controller.V030controller;
import queenb.web.crm.store.CustomerStore;
import queenb.web.store.C575Store;
import queenb.web.store.K300Store;
import queenb.web.store.Q000Store;
import queenb.web.util.SessionName;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class C575Controller extends QueenbController {

    private int PC575;
    private int FV500;
    private int FC425;
    private int FC475;
    private int FN100;
    private int FIDS;
    private int CN578;
    private int CN588;
    private int CN589;
    private int CN590;
    private Date CD585;
    private Date CD586;
    private Date CD587;
    private String CV576;
    private String CV577;
    private String CV579;
    private String CV580;
    private String CV581;
    private String CV582;
    private String CV583;
    private String CV584;
    private int IDPER;// nguoi chiu trac hnhiem cong viec
    private List<SelectItem> cbbC425 = new ArrayList<SelectItem>();
    private List<SelectItem> cbbC475 = new ArrayList<SelectItem>();
    private List<C575> ccurpks_listoftabc575;
    private C575Store c575Store;
    private List<C575> listC575 = new ArrayList<C575>();
    private String nameMail;
    private String passMail;

    public C575Controller() {
        c575Store = new C575Store();
        Object action = getRequest().getParameter("action");
        if (action != null) {
            if (action.equals("getListC575")) {
                Object pn100Obj = getRequest().getParameter("pn100");
                if (pn100Obj != null) {
                    FIDS = Util.parseInt(pn100Obj);
                    FN100 = Integer.parseInt(pn100Obj.toString());
                }
                Object fc475Obj = getRequest().getParameter("fc475");
                if (fc475Obj != null) {
                    FC475 = Util.parseInt(fc475Obj);
                    SessionProvider.setSessionMapValue("IDFC475QT", FC475);
                }
                System.out.println("----------FN100---" + FIDS + FC475);
            } else if (action.equals("updateC575")) {
                Object objPC575 = getRequest().getParameter("PC575");
                Object objCV580 = getRequest().getParameter("CV580");
                System.out.println("-----updatec575----");
                Object objFN100 = getRequest().getParameter("FN100");
                if (objPC575 != null && objCV580 != null && objFN100 != null) {
                    PC575 = Integer.parseInt(objPC575.toString());
                    CV580 = objCV580.toString();
                    FN100 = Integer.parseInt(objFN100.toString());
                    System.out.println("-----updatec575--abc--:" + PC575 + "---" + CV580);
//                   updateC575(Integer.parseInt(objPC575.toString()),objCV580.toString());
                }

            } else if (action.equals("getvalueFN100")) {
                Object objPC575 = getRequest().getParameter("fn100");

                if (objPC575 != null) {
                    SessionProvider.setSessionMapValue("IDGETVALUEFN100", objPC575);
                }
                Object objPC5752 = getRequest().getParameter("FN100");

                if (objPC5752 != null) {
                    FN100 = Integer.parseInt(objPC5752.toString());
                }
                Object objPC5751 = getRequest().getParameter("pc575");
                if (objPC5751 != null) {
                    PC575 = Integer.parseInt(objPC5751.toString());
                }

                Object objCV = getRequest().getParameter("cv");
                if (objCV != null) {
                    SessionProvider.setSessionMapValue("NAMECVC575", objCV);
                }
                Object objnameMail = getRequest().getParameter("namemail");
                if (objnameMail != null) {
                    SessionProvider.setSessionMapValue("NAMEMAILC575", objnameMail);
                }
                Object objnameMail1 = getRequest().getParameter("hotenyc");
                if (objnameMail1 != null) {
                    SessionProvider.setSessionMapValue("NAMEYCC575", objnameMail1);
                }
                getQ000SendById();
            }
        }
    }

    public void saveOnchangeFn100() {
        try {
            CustomerStore sr = new CustomerStore();
            int count = sr.updateColumnN100(null, "C575", "FN100", SessionProvider.getSessionMapValue("IDGETVALUEFN100").toString(), "PC575", PC575, getLogin().getUserName());
            if (count != 0) {
                showGlobalReport(true, getResourceString("success"));

            } else {
                showGlobalReport(true, getResourceString("error"));
            }
            int FV050 = 0;
            if (SessionProvider.getSessionMapValue("codetourselect") != null) {
                FV050 = Integer.parseInt(SessionProvider.getSessionMapValue("codetourselect").toString());
            }
            if (SessionProvider.getSessionMapValue("IDGETVALUEFN100") != null) {
                SessionProvider.removeSessionMapValue("IDGETVALUEFN100");
            }
            Date date = new Date();
            String contentMail = "Công việc do " + SessionProvider.getSessionMapValue("NAMEYCC575") + " giao nhiệm vụ cho nhân viên " + SessionProvider.getSessionMapValue("NAMEMAILC575") + " với Công việc " + SessionProvider.getSessionMapValue("NAMECVC575") + "</br>"
                    + " Thuộc code Tour " + SessionProvider.getSessionMapValue(SessionName.TOUR_CODE) + " tên Tour " + SessionProvider.getSessionMapValue(SessionName.TOUR_NAME) + " Vui lòng đăng nhập www.kapi.saigon-travel.com để nhận công việc ngày" + date + ".";

            String nameM = null;
            String passM = null;
            String mailto = null;
            if (SessionProvider.getSessionMapValue("NAMEEMAILSEND") != null) {
                nameM = SessionProvider.getSessionMapValue("NAMEEMAILSEND").toString();
            }
            if (SessionProvider.getSessionMapValue("PASSEMAILSEND") != null) {
                passM = SessionProvider.getSessionMapValue("PASSEMAILSEND").toString();
            }
            
            if (SessionProvider.getSessionMapValue("NAMEMAILC575") != null) {
                mailto = SessionProvider.getSessionMapValue("NAMEMAILC575").toString();
            }
            System.out.println("---------- THAM SO MAIL-------" + nameM + passM + SessionProvider.getSessionMapValue("NAMEMAILC575") + contentMail);
            N500Controller n500Controller = new N500Controller();
            n500Controller.sendMail(nameM, passM,mailto, "CÔNG VIỆC CHECK THỦ TỤC VISA", contentMail);
            sendRedirectUrlTab("customer4tour.jsp?status=T&action=delSS&tab=upitem" + FN100 + "&pv050=" + FV050 + "&" + Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    public void changeCV580() {
        System.out.println("-----changeCV580----:" + CV580);
    }

    private void updateC575(int pnPC575, String pvCV580) {
        try {
            CustomerStore cus = new CustomerStore();
            System.out.println("-----updatec575----:" + pnPC575 + "-----" + pvCV580);
//            int rs =  c575Store.updateC575(pnPC575, "F", pvCV580, getLogin().getUserName());
            int rs = cus.updateColumnN100(null, "C575", "CV579", "F", "PC575", pnPC575, getLogin().getUserName());
            int rs2 = cus.updateColumnN100(null, "C575", "CV580", pvCV580, "PC575", pnPC575, getLogin().getUserName());
            System.out.println("-----updatec575----:" + rs + "---:" + rs2);
        } catch (Exception e) {
        }
    }

    public void updateC575_up() {
        try {
            CustomerStore cus = new CustomerStore();
            System.out.println("-----updatec575---aaaa-:" + PC575 + "-----" + CV580);
//            int rs =  c575Store.updateC575(pnPC575, "F", pvCV580, getLogin().getUserName());
            int rs = cus.updateColumnN100(null, "C575", "CV579", "F", "PC575", PC575, getLogin().getUserName());
            int rs2 = cus.updateColumnN100(null, "C575", "CV580", CV580, "PC575", PC575, getLogin().getUserName());
            if (rs > 0 && rs2 > 0) {
                showGlobalReport(true, getResourceString("success"));

            } else {
                showGlobalReport(true, getResourceString("error"));
            }
            // status=T&pv050=536&action=delSS&tourname=Đà lạt - Đà nẳng
            String tourname = null;
            if (SessionProvider.getSessionMapValue(SessionName.TOUR_NAME) != null) {
                tourname = SessionProvider.getSessionMapValue(SessionName.TOUR_NAME).toString();
                System.out.println("------------------tourname-:" + tourname);
            }
            int FV050 = 0;
            if (SessionProvider.getSessionMapValue("codetourselect") != null) {
                FV050 = Integer.parseInt(SessionProvider.getSessionMapValue("codetourselect").toString());
            }
            sendRedirectUrlTab("customer4tour.jsp?status=T&action=delSS&tab=upitem" + FN100 + "&pv050=" + FV050 + "&" + Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    public void stdc_tools_inserttabc575() {
        try {
            //  System.out.println("-----THAM SO-----" + PC350 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + FC425 + "," + CN351 + "," + pvCV352 + "," + pvCV353 + "," + getLogin().getUserName());
            int count = c575Store.stdc_tools_inserttabc575(PC575, getLogin().getModule(), FV500, FC425, FC475, FN100, FIDS, CV576, CV577, CN578, CV579, CV580, CV581, CV582, CV583, CV584, Util.toSQLDate(CD585), Util.toSQLDate(CD586), Util.toSQLDate(CD587), CN588, CN589, CN590, getLogin().getUserName());
            if (count != 0) {
                showGlobalReport(true, getResourceString("success"));

            } else {
                showGlobalReport(true, getResourceString("error"));
            }

            sendRedirectUrlTab("setting.jsp?tab=header33&llinkC425=" + Util.convertMD5(getRequest().getRequestURI()));
        } catch (Exception e) {
        }
    }

    /**
     * @return the PC575
     */
    public int getPC575() {
        return PC575;
    }

    /**
     * @param PC575 the PC575 to set
     */
    public void setPC575(int PC575) {
        this.PC575 = PC575;
    }

    /**
     * @return the FV500
     */
    public int getFV500() {
        return FV500;
    }

    /**
     * @param FV500 the FV500 to set
     */
    public void setFV500(int FV500) {
        this.FV500 = FV500;
    }

    /**
     * @return the FC425
     */
    public int getFC425() {
        return FC425;
    }

    /**
     * @param FC425 the FC425 to set
     */
    public void setFC425(int FC425) {
        this.FC425 = FC425;
    }

    /**
     * @return the FC475
     */
    public int getFC475() {
        return FC475;
    }

    /**
     * @param FC475 the FC475 to set
     */
    public void setFC475(int FC475) {
        this.FC475 = FC475;
    }

    /**
     * @return the FN100
     */
    public int getFN100() {
        return FN100;
    }

    /**
     * @param FN100 the FN100 to set
     */
    public void setFN100(int FN100) {
        this.FN100 = FN100;
    }

    /**
     * @return the FIDS
     */
    public int getFIDS() {
        return FIDS;
    }

    /**
     * @param FIDS the FIDS to set
     */
    public void setFIDS(int FIDS) {
        this.FIDS = FIDS;
    }

    /**
     * @return the CN578
     */
    public int getCN578() {
        return CN578;
    }

    /**
     * @param CN578 the CN578 to set
     */
    public void setCN578(int CN578) {
        this.CN578 = CN578;
    }

    /**
     * @return the CN588
     */
    public int getCN588() {
        return CN588;
    }

    /**
     * @param CN588 the CN588 to set
     */
    public void setCN588(int CN588) {
        this.CN588 = CN588;
    }

    /**
     * @return the CN589
     */
    public int getCN589() {
        return CN589;
    }

    /**
     * @param CN589 the CN589 to set
     */
    public void setCN589(int CN589) {
        this.CN589 = CN589;
    }

    /**
     * @return the CN590
     */
    public int getCN590() {
        return CN590;
    }

    /**
     * @param CN590 the CN590 to set
     */
    public void setCN590(int CN590) {
        this.CN590 = CN590;
    }

    /**
     * @return the CD585
     */
    public Date getCD585() {
        return CD585;
    }

    /**
     * @param CD585 the CD585 to set
     */
    public void setCD585(Date CD585) {
        this.CD585 = CD585;
    }

    /**
     * @return the CD586
     */
    public Date getCD586() {
        return CD586;
    }

    /**
     * @param CD586 the CD586 to set
     */
    public void setCD586(Date CD586) {
        this.CD586 = CD586;
    }

    /**
     * @return the CD587
     */
    public Date getCD587() {
        return CD587;
    }

    /**
     * @param CD587 the CD587 to set
     */
    public void setCD587(Date CD587) {
        this.CD587 = CD587;
    }

    /**
     * @return the CV576
     */
    public String getCV576() {
        return CV576;
    }

    /**
     * @param CV576 the CV576 to set
     */
    public void setCV576(String CV576) {
        this.CV576 = CV576;
    }

    /**
     * @return the CV577
     */
    public String getCV577() {
        return CV577;
    }

    /**
     * @param CV577 the CV577 to set
     */
    public void setCV577(String CV577) {
        this.CV577 = CV577;
    }

    /**
     * @return the CV579
     */
    public String getCV579() {
        return CV579;
    }

    /**
     * @param CV579 the CV579 to set
     */
    public void setCV579(String CV579) {
        this.CV579 = CV579;
    }

    /**
     * @return the CV580
     */
    public String getCV580() {
        return CV580;
    }

    /**
     * @param CV580 the CV580 to set
     */
    public void setCV580(String CV580) {
        this.CV580 = CV580;
    }

    /**
     * @return the CV581
     */
    public String getCV581() {
        return CV581;
    }

    /**
     * @param CV581 the CV581 to set
     */
    public void setCV581(String CV581) {
        this.CV581 = CV581;
    }

    /**
     * @return the CV582
     */
    public String getCV582() {
        return CV582;
    }

    /**
     * @param CV582 the CV582 to set
     */
    public void setCV582(String CV582) {
        this.CV582 = CV582;
    }

    /**
     * @return the CV583
     */
    public String getCV583() {
        return CV583;
    }

    /**
     * @param CV583 the CV583 to set
     */
    public void setCV583(String CV583) {
        this.CV583 = CV583;
    }

    /**
     * @return the CV584
     */
    public String getCV584() {
        return CV584;
    }

    /**
     * @param CV584 the CV584 to set
     */
    public void setCV584(String CV584) {
        this.CV584 = CV584;
    }

    /**
     * @return the ccurpks_listoftabc575
     */
    public List<C575> getCcurpks_listoftabc575() {
        try {
            V030controller v030 = new V030controller();
            System.out.println("---------THAM SO-------" + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + Util.parseInt(SessionProvider.getSessionMapValue("IDFC475QT")) + "," + FIDS + "," + v030.getFV050() + "," + getLogin().getUserName());
            ccurpks_listoftabc575 = c575Store.ccurpks_listoftabc575(getLogin().getModule(), getLogin().getCompanyNo(), Util.parseInt(SessionProvider.getSessionMapValue("IDFC475QT")), FIDS, v030.getFV050(), getLogin().getUserName());

            return ccurpks_listoftabc575;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * @param ccurpks_listoftabc575 the ccurpks_listoftabc575 to set
     */
    public void setCcurpks_listoftabc575(List<C575> ccurpks_listoftabc575) {
        this.ccurpks_listoftabc575 = ccurpks_listoftabc575;
    }

    /**
     * @return the c575Store
     */
    public C575Store getC575Store() {
        return c575Store;
    }

    /**
     * @param c575Store the c575Store to set
     */
    public void setC575Store(C575Store c575Store) {
        this.c575Store = c575Store;
    }

    /**
     * @return the cbbC425
     */
    public List<SelectItem> getCbbC425() {
        return cbbC425;
    }

    /**
     * @param cbbC425 the cbbC425 to set
     */
    public void setCbbC425(List<SelectItem> cbbC425) {
        this.cbbC425 = cbbC425;
    }

    /**
     * @return the cbbC475
     */
    public List<SelectItem> getCbbC475() {
        return cbbC475;
    }

    /**
     * @param cbbC475 the cbbC475 to set
     */
    public void setCbbC475(List<SelectItem> cbbC475) {
        this.cbbC475 = cbbC475;
    }

    /**
     * @return the listC575
     */
    public List<C575> getListC575() {
        return listC575;
    }

    /**
     * @param listC575 the listC575 to set
     */
    public void setListC575(List<C575> listC575) {
        this.listC575 = listC575;
    }

    /**
     * @return the IDPER
     */
    public int getIDPER() {
        return IDPER;
    }

    /**
     * @param IDPER the IDPER to set
     */
    public void setIDPER(int IDPER) {
        this.IDPER = IDPER;
    }

    public void getQ000SendById() {
        Q000Store q000Store = new Q000Store();
        List<Q000> lst = q000Store.getListQ000(getLogin().getModule(), getLogin().getCompanyNo(), getLogin().getId(), getLogin().getUserName());
        if (lst != null) {
            System.out.println("T:- list getListAllQ000ByIDofMyprofile: " + lst.size());
        } else {
            System.out.println("T:- list getListAllQ000ByIDofMyprofile: null");
        }

        this.nameMail = lst.get(0).getQV001();
        if (nameMail != null) {
            SessionProvider.setSessionMapValue("NAMEEMAILSEND", nameMail);
        }
        this.passMail = lst.get(0).getQV002();
        if (passMail != null) {
            SessionProvider.setSessionMapValue("PASSEMAILSEND", passMail);
        }
        System.out.println("------------EMAILLLLLLLLLLLLLLL--------" + nameMail + passMail);

    }
}
